package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.pojo.Admin;
import com.example.demo.mapper.AdminMapper;
import com.example.demo.service.AdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sjy
 * @since 2025-05-25
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public ResultVO<Admin> adminLogin(String account, String password) throws Exception {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account", account);
        Admin admin = adminMapper.selectOne(queryWrapper);
        if(admin != null){
            if(admin.getPassword().equals(password)){
                return ResultVO.success("登录成功", admin);
            }
            return ResultVO.fail("密码错误");
        }
        return ResultVO.fail("账号不存在");
    }
}
